package com.example.s8_dingcan.controller;

import com.example.s8_dingcan.pojo.BaseResult;
import com.example.s8_dingcan.pojo.Category;
import com.example.s8_dingcan.service.ICategoryService;
import com.fasterxml.jackson.databind.ser.Serializers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category/")
public class CategoryController
{

    @Autowired
    private ICategoryService categoryService;

    @RequestMapping("/{id}")
    public BaseResult<Category> findOne(@PathVariable(value = "id") int id)
    {
        Category r =  categoryService.getById(id);
        return BaseResult.success(r);
    }

    @RequestMapping("/")
    public BaseResult<List<Category>> findOne()
    {
        return BaseResult.success(categoryService.list());
    }
}
